//
//  comBlueboxmoonPhoneWebAddress.m
//  WebAddress
//
//  Created by Daniel Hazelbaker on 10/27/10.
//  Copyright 2010 High Desert Church. All rights reserved.
//

#import "comBlueboxmoonPhoneWebAddress.h"
#import "BMSnomPhone.h"


@implementation comBlueboxmoonPhoneWebAddress


//
// Set the default preferences.
//
+ (void)setDefaultPreferences
{
    BMPreferences   *prefs = [BMSnomPhone preferences];


    if ([prefs valueForKey:kWebAddressWebAddressKey] == nil)
	[prefs setValue:@"" forKey:kWebAddressWebAddressKey];
}



#pragma mark BMPluginHandlerProtocol
//////////////////////////////////////////////////////////////////////////
//
// BMPluginHandlerProtocol
//
//////////////////////////////////////////////////////////////////////////


//
// The phone address lookup continues until the first plugin returns a
// non-nil result, indicating that it found the IP address (or host name)
// we are looking for.
//
- (NSString *)lookupPhoneAddress
{
    NSURLRequest    *request;
    NSData	    *data;
    
    
    request = [NSURLRequest requestWithURL:[NSURL URLWithString:[[BMSnomPhone preferences] valueForKey:kWebAddressWebAddressKey]]];
    data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    if (data != nil)
	return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
	
    return nil;
}


@end
